<template>
  <div>
    <top-bar></top-bar>
    <left-bar :datas='data'></left-bar>
    <div class="orders system">
      <home-bar :currentPage='currentPage'></home-bar>
      <div class="order-main system-main">
        <div class="main-position">
          首页 > 订单管理 > {{currentPageName}}
        </div>
        <div class="main-height"></div>
        <div class="main-mains">
          <div class="main-top-nav">
            <ul>
              <router-link to="/allorders/all" @click.native="addPath('/allorders/all','订单管理'); determineRouting('全部订单',0)">
                <li :class="{active:this.$route.params.id=='all'}">全部订单</li>
              </router-link>
              <router-link to="/allorders/unconfirmed" @click.native="addPath('/allorders/unconfirmed','订单管理');determineRouting('未确认订单',2)">
                <li :class="{active:this.$route.params.id=='unconfirmed'}">未确认订单</li>
              </router-link>
              <router-link to="/allorders/pendingdelivery" @click.native="addPath('/allorders/pendingdelivery','订单管理');determineRouting('待发货订单',3)">
                <li :class="{active:this.$route.params.id=='pendingdelivery'}">待发货订单</li>
              </router-link>
              <router-link to="/allorders/alreadyshipped" @click.native="addPath('/allorders/alreadyshipped','订单管理');determineRouting('已发货订单',4)">
                <li :class="{active:this.$route.params.id=='alreadyshipped'}">已发货订单</li>
              </router-link>
              <router-link to="/allorders/settleds" @click.native="addPath('/allorders/settleds','订单管理');determineRouting('已结算订单',5)">
                <li :class="{active:this.$route.params.id=='settleds'}">已结算订单</li>
              </router-link>
            </ul>
          </div>
          <div class="orderInner">
            <div class="moreScreeningKeyword" v-show="moreScreeningKeyword">
              <li v-for="(screening,index) in moreScreeningKeywordList" :key="index">
                <span>{{screening.key}}：</span>
                <span>{{screening.searchWord}}</span>
                <i class="el-icon-close" @click="deleteScreeningKeywordItem(index)"></i>
              </li>
            </div>
            <div class="headOperation">
              <a href="javascript:void(0);" class="OperationA" @click="clickScreeningPopup">筛选</a>
              <div class="drugListSearch">
                <el-input placeholder="请输入内容" v-model="searchKeyWords">
                  <i slot="suffix" class="el-input__icon el-icon-search" @click="getList(searchKeyWords)"></i>
                </el-input>
              </div>
              <a href="javascript:void(0);" class="OperationA-color" @click="clearScreeningConditions()" v-if="iconDownSwitch">清空筛选条件</a>
              <i class="iconDown iconfont icon-xiala" @click="moreScreeningKeyword = moreScreeningKeyword == false ? true : false" v-if="iconDownSwitch"></i>
              <div class="screeningKeyword">
                <span v-for="(screening,index) in this.moreScreeningKeywordList" :key="index">
                                      {{screening.searchWord.length > 6 ? screening.searchWord.slice(0,6) + '...' : screening.searchWord}}
                                      <i class="el-icon-close" @click="deleteScreeningKeywordItem(index)"></i>
                                    </span>
              </div>
            </div>
            <div class="orderItem" v-for="(item,index) in tableList" :key="index">
              <div class="orderItemTop">
                <el-checkbox class="fl" v-model='checkArr' :label="item.id" @change="changevalue"></el-checkbox>
                <span class="fl orderTime">{{item.order_time}}</span>
                <span class="fl">订单编号: <em>{{item.order_no}}</em></span>
                <span class="fr">获得积分：<em>{{item.total}}</em></span>
              </div>
              <table>
                <tbody>
                  <tr>
                    <td>
                      <div class="drugImgBox">
                        <img :src="item.image_url" alt="">
                        <i class="newOrderTip" v-if="item.status == 2"></i>
                      </div>
                      <div class="drugMsg">
                        <h5>包含药品：{{item.medical_count}}款</h5>
                        <p>客户：{{item.client_name}}<br> 来源： {{item.referer == 1?"PC商城":"APP"}}</p>
                      </div>
                    </td>
                    <td>
                      <h5>￥{{item.amount}}</h5>
                      <span>订单总价</span>
                    </td>
                    <td>
                      <h5>￥{{item.info_fee}}</h5>
                      <span>信息费</span>
                    </td>
                    <td>
                      <h5>订单状态</h5>
                      <span>{{item.status | statusFun}}</span>
                    </td>
                    <td>
                      <div>
                        <router-link :to="{name:'orderdetails',params:{id:item.status,oid:item.order_id}}" @click.native="addPath('/orderdetails/'+item.status+'/'+item.order_id,'订单管理')">
                          <el-button type="primary" size="small">订单详情</el-button>
                        </router-link>
                        <el-button type="warning" size="small" @click="clickConfirmOrder(item.order_id)" v-if="item.status == 0 || item.status == 2">确认订单</el-button>
                      </div>
                    </td>
                    <td>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="pageBotom">
              <!-- <div class="pageBotomLeft">
                                              <el-checkbox class="fl" v-model='cheackAllChecked' @change='checkAllFun'>全选</el-checkbox>
                                              <span class="reverseSelected" @click="reverseChecked">反选</span>
                                              <span class="deleteSelected">删除选中</span>
                                            </div> -->
              <div class="pageBotomRight">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage4" :page-size="20" layout="total, prev, pager, next" :total="totalNumOfArticle">
                </el-pagination>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="system-menban" v-show="showSystemPopup">
      </div>
      <div class="systemPopup" v-show="showSystemPopup">
        <div class="topTitle">
          <span>{{systemPopupTitle}}</span>
          <i class="el-icon-close system-icon" @click="hideSystemPopup"></i>
        </div>
        <!-- 筛选弹窗 -->
        <div class="screeningPopup clear" v-show="showScreeningPopup">
          <ul class="clear">
            <li>
              <span class="spanTitle">下单日期</span>
              <div class="inputBox doubleInputBox">
                <el-date-picker v-model="screeningValueList.minDate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="timestamp">
                </el-date-picker>
                <span class="horizontalLine"></span>
                <el-date-picker v-model="screeningValueList.maxDate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="timestamp">
                </el-date-picker>
              </div>
            </li>
            <li>
              <span class="spanTitle">来源</span>
              <div class="inputBox">
                <el-select v-model="screeningValueList.from">
                  <el-option v-for="item in fromOptions" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </div>
            </li>
            <li>
              <span class="spanTitle">品牌名称</span>
              <div class="inputBox">
                <el-input type="text" v-model="screeningValueList.searchKey" placeholder="请输入订单号，买家名称，药品名称"></el-input>
              </div>
            </li>
          </ul>
          <div class="system-messagebox1-btn clear">
            <div @click="clickSureScreening(showStatus)">确定</div>
            <div @click="hideSystemPopup">取消</div>
          </div>
        </div>
        <!--/.screeningPopup -->
        <!-- 确认订单弹窗 -->
        <div class="orderDetailPopup" v-show="showOrderDetailPopup">
          <ul>
            <li v-for="(item,index) in order.medical_list" :key="index">
              <div class="topMsg"><span>药品名称：{{item.medical_name}}</span></div>
              <div class="numBox">
                <span class="leftTitle">客户下单数量</span>
                <div class="rightContent">{{item.total}}</div>
              </div>
              <div class="numBox">
                <span class="leftTitle">确定有货数量</span>
                <div class="rightContent">
                  <el-input v-model="confirmTotalList[index]" @change="changeTotalNum(item.total,confirmTotalList[index],index,item.medical_id)" type="number"></el-input>
                </div>
              </div>
              <div class="orderState">
                <div ref="enoughDrug">订单正常发货</div>
                <div ref="lackDrug">
                  <h5>数量与订单数量不符，订单金额将自动调整：</h5>
                  <table>
                    <tbody>
                      <tr>
                        <td>调整后订单总价</td>
                        <td>￥{{confirmTotalList[index]*item.price}}</td>
                      </tr>
                      <tr>
                        <td>调整后实际到账货款</td>
                        <td>￥{{(confirmTotalList[index]*item.price)-(item.price*confirmTotalList[index]*item.info_fee_rate)}}</td>
                      </tr>
                      <tr>
                        <td>将向买家退回</td>
                        <td>￥{{item.amount - confirmTotalList[index]*item.price}}</td>
                      </tr>
                      <tr>
                        <td>调整后到账积分</td>
                        <td>{{parseInt((item.price*confirmTotalList[index]*item.info_fee_rate)/ 0.24 * 0.36)}}分</td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </li>
          </ul>
          <div class="system-messagebox1-btn clear">
            <div @click="clickChangeTotal(3)">确定</div>
            <div @click="hideSystemPopup">取消</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import topBar from "../../public/top";
  import leftBar from "../../public/left";
  import homeBar from "../../public/homebar";
  export default {
    components: {
      leftBar,
      topBar,
      homeBar
    },
    data() {
      return {
        data: "/allorders",
        currentPageName: "全部订单",
        currentPage: {
          path: "/allorders/all",
          name: "订单管理"
        },
        ids: "",
        checked: true,
        currentPage4: 4,
        totalNumOfArticle: 1,
        showPageNum: 1, //要展示的页展示的页码
        showSystemPopup: false,
        systemPopupTitle: "筛选条件",
        showOrderDetailPopup: false,
        showScreeningPopup: false,
        //筛选
        screeningValueList: {
          minDate: "", //开始下单日期
          maxDate: "", //结束下单日期
          from: "", //来源
          searchKey: "", //品牌名称
        },
        fromOptions: [{
            value: 1,
            label: "pc商城"
          },
          {
            value: 2,
            label: "app"
          }
        ],
        //筛选结果列表
        moreScreeningKeywordList_org: [{
            moreScreeningKeywordList: [], //全部订单（0）
          },
          {
            moreScreeningKeywordList: [], //空（1）
          },
          {
            moreScreeningKeywordList: [], //未确认订单（2）
          },
          {
            moreScreeningKeywordList: [], //待发货订单（3）
          },
          {
            moreScreeningKeywordList: [], //已发货订单（4）
          },
          {
            moreScreeningKeywordList: [], //已结算订单（5）
          },
        ],
        moreScreeningKeywordList: [],
        moreScreeningKeyword: false, //（筛选关键字下拉框）开关
        iconDownSwitch: false, //（筛选关键字下拉按钮）开关
        tableList: [],
        cheackAllChecked: false,
        checkArr: [],
        checkCompleteArr: [],
        showStatus: 1, //请求的status
        searchKeyWords: "",
        order: "",
        confirmTotalList: [],
        order_id: "", //订单id
        new_medical_list: [], //当status=2时并且有修改订单药品数量必传
        changeStatus:true,  //false的时候说明输入的确认有货数量不符合要求，不能点击确认订单
      };
    },
    activated() {
      this.ids = '/orderdetails/' + this.$route.params.id;
      //全选或反选用到的完整数组值（5/5）
      var _this = this;
      this.tableList.forEach(function(item, index) {
        if (index >= 0) {
          _this.checkCompleteArr.push(item.id);
        }
      });
      const routeParamsId = this.$route.params.id;
      if (routeParamsId == "all") {
        //全部订单
        this.showStatus = 0;
        this.currentPageName = "全部订单";
      } else if (routeParamsId == "unconfirmed") {
        //未确认订单
        this.showStatus = 2;
        this.currentPageName = "未确认订单";
      } else if (routeParamsId == "pendingdelivery") {
        //待发货订单
        this.showStatus = 3;
        this.currentPageName = "待发货订单";
      } else if (routeParamsId == "alreadyshipped") {
        //已发货订单
        this.showStatus = 4;
        this.currentPageName = "已发货订单";
      } else if (routeParamsId == "settleds") {
        //已结算订单
        this.showStatus = 5;
        this.currentPageName = "已结算订单";
      }
      this.getList();
    },
    methods: {
      //错误弹窗
      messageAlert(msg) {
        this.$message.error(msg);
      },
      //成功弹窗
      successfulAlert(msg) {
        this.$message({
          message: msg,
          type: 'success'
        });
      },
      //提示框
      infoAlert(msg) {
        this.$message(msg);
      },
      //获取订单列表（包括获取筛选列表）
      getList(searchKeyWords) {
        var date_range = "";
        var referer = "";
        var search_key = "";
        if (searchKeyWords != undefined && searchKeyWords != "") {
          search_key = "&search_key=" + searchKeyWords;
        }
        for (var i in this.moreScreeningKeywordList) {
          if (this.showStatus == this.moreScreeningKeywordList[i].status) {
            //下单日期（筛选）
            if (this.moreScreeningKeywordList[i].key == "下单日期") {
              date_range = "&date_range=" + this.moreScreeningKeywordList[i].value;
            }
            //来源（筛选）
            else if (this.moreScreeningKeywordList[i].key == "来源") {
              referer = "&referer=" + this.moreScreeningKeywordList[i].value;
            }
            //搜索关键字（筛选）
            else if (this.moreScreeningKeywordList[i].key == "搜索关键字") {
              search_key = "&search_key=" + this.moreScreeningKeywordList[i].value;
            }
          }
        }
        let _this = this;
        let ourls =
          this.urls +
          "/who/user/refreshToken/" +
          localStorage.getItem("uid") +
          "/" +
          localStorage.getItem("token");
        checkTime(
          new Date().getTime() / 1000,
          ourls,
          localStorage.getItem("reToken")
        );
        _this
          .$http({
            url: this.urls +
              "/who/order/getOrderList/" +
              localStorage.getItem("uid") +
              "/" +
              localStorage.getItem("token") +
              "/?page=" +
              this.showPageNum + "&status=" + _this.showStatus + date_range + referer + search_key,
            method: "get"
          })
          .then(function(res) {
            let data = res.data;
            if (data.code == 1) {
              _this.tableList = data.data.order_list;
              _this.totalNumOfArticle = data.data.total;
              _this.hideSystemPopup();
              localStorage.setItem("nowTimes", new Date().getTime() / 1000); //检查token失效函数
            } else {
              _this.messageAlert(data.msg);
              invalid(data.msg); //检查token失效函数
            }
          })
          .catch(function(error) {
            console.log(error);
          });
      },
      //点击筛选弹窗中的确定
      clickSureScreening(status) {
        var ai = false;
        if (this.moreScreeningKeywordList_org[status].moreScreeningKeywordList.length <= 0) {
          ai = true;
        }
        //下单日期
        if (this.screeningValueList.minDate != "" || this.screeningValueList.maxDate != "") {
          this.screeningValueList.minDate = this.screeningValueList.minDate / 1000;
          this.screeningValueList.maxDate = this.screeningValueList.maxDate / 1000;
          var bi = true;
          if (this.screeningValueList.minDate > this.screeningValueList.maxDate) {
            this.messageAlert("请填写正确的日期范围");
            return;
          } else if (this.screeningValueList.minDate == "" || this.screeningValueList.maxDate == "") {
            this.messageAlert("请填写完整的日期范围");
            return;
          } else {
            if (this.moreScreeningKeywordList_org[status].moreScreeningKeywordList.length >= 1) {
              for (var i = 0; i < this.moreScreeningKeywordList_org[status].moreScreeningKeywordList.length; i++) {
                if (this.moreScreeningKeywordList_org[status].moreScreeningKeywordList[i].value != this.screeningValueList.minDate + '-' + this.screeningValueList.maxDate) {
                  ai = true;
                } else {
                  bi = false;
                }
              }
            }
            if (ai && bi && this.showStatus == status) {
              this.moreScreeningKeywordList_org[status].moreScreeningKeywordList.push({
                key: "下单日期",
                value: this.screeningValueList.minDate + "-" + this.screeningValueList.maxDate,
                status: status,
                searchWord: this.changeG(this.screeningValueList.minDate) + "-" + this.changeG(this.screeningValueList.maxDate)
              });
              this.moreScreeningKeywordList.push({
                key: "下单日期",
                value: this.screeningValueList.minDate + "-" + this.screeningValueList.maxDate,
                status: status,
                searchWord: this.changeG(this.screeningValueList.minDate) + "-" + this.changeG(this.screeningValueList.maxDate)
              });
            }
          }
        }
        //来源
        if (this.screeningValueList.from != "") {
          var bi = true;
          var searchWord = "";
          if (this.screeningValueList.from == 1) {
            searchWord = "PC商城";
          } else if (this.screeningValueList.from == 2) {
            searchWord = "APP"
          }
          if (this.moreScreeningKeywordList_org[status].moreScreeningKeywordList.length >= 1) {
            for (var i = 0; i < this.moreScreeningKeywordList_org[status].moreScreeningKeywordList.length; i++) {
              if (this.moreScreeningKeywordList_org[status].moreScreeningKeywordList[i].searchWord != this.screeningValueList.from) {
                ai = true;
              } else {
                bi = false;
              }
            }
          }
          if (ai && bi && this.showStatus == status) {
            this.moreScreeningKeywordList_org[status].moreScreeningKeywordList.push({
              key: "来源",
              value: this.screeningValueList.from,
              status: status,
              searchWord: searchWord
            });
            this.moreScreeningKeywordList.push({
              key: "来源",
              value: this.screeningValueList.from,
              status: status,
              searchWord: searchWord
            });
          }
        }
        //搜索关键字
        if (this.screeningValueList.searchKey != "") {
          var bi = true;
          if (this.moreScreeningKeywordList_org[status].moreScreeningKeywordList.length >= 1) {
            for (var i = 0; i < this.moreScreeningKeywordList_org[status].moreScreeningKeywordList.length; i++) {
              if (this.moreScreeningKeywordList_org[status].moreScreeningKeywordList[i].searchWord != this.screeningValueList.searchKey) {
                ai = true;
              } else {
                bi = false;
              }
            }
          }
          if (ai && bi && this.showStatus == status) {
            this.moreScreeningKeywordList_org[status].moreScreeningKeywordList.push({
              key: "搜索关键字",
              value: this.screeningValueList.searchKey,
              status: status,
              searchWord: this.screeningValueList.searchKey
            });
            this.moreScreeningKeywordList.push({
              key: "搜索关键字",
              value: this.screeningValueList.searchKey,
              status: status,
              searchWord: this.screeningValueList.searchKey
            });
          }
        }
        if (this.moreScreeningKeywordList.length > 0) {
          this.iconDownSwitch = true;
        }
        this.getList();
      },
      //点击删除单个筛选关键词
      deleteScreeningKeywordItem(index) {
        this.moreScreeningKeywordList.splice(index, 1);
        this.getList();
        if (this.moreScreeningKeywordList.length == 0) {
          this.moreScreeningKeyword = false;
          this.iconDownSwitch = false;
        }
      },
      //点击清空筛选条件
      clearScreeningConditions() {
        this.$confirm("此操作将删除所有筛选记录?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            this.successfulAlert("删除成功!");
            this.moreScreeningKeywordList = [];
            this.moreScreeningKeywordList_org[this.showStatus].moreScreeningKeywordList = [];
            this.moreScreeningKeyword = false;
            this.iconDownSwitch = false;
            this.getList();
          })
          .catch(() => {
            this.infoAlert("已取消删除");
          });
      },
      //转为两位小数
      changeG(value) {
        var time = new Date(value * 1000);
        var month = (time.getMonth() + 1) > 9 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1);
        var data = time.getDate() > 9 ? time.getDate() : '0' + (time.getDate());
        var hour = time.getHours() > 9 ? time.getHours() : '0' + (time.getHours());
        var minutes = time.getMinutes() > 9 ? time.getMinutes() : '0' + (time.getMinutes());
        var second = time.getSeconds() > 9 ? time.getSeconds() : '0' + (time.getSeconds());
        var times = time.getFullYear() + "-" + month + "-" + data
        return times;
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.showPageNum = val;
        this.getList();
      },
      clickScreeningPopup() {
        this.showSystemPopup = true;
        this.showScreeningPopup = true;
      },
      //关闭弹窗
      hideSystemPopup() {
        this.showSystemPopup = false;
        this.showScreeningPopup = false;
        this.systemPopupTitle = "";
        this.screeningValueList.minDate = "";
        this.screeningValueList.maxDate = "";
        this.screeningValueList.from = "";
        this.screeningValueList.searchKey = "";
        this.showOrderDetailPopup = false;
      },
      //点击确认订单
      clickConfirmOrder(orderId) {
        this.getOrderDetail(orderId); //获取订单信息
        this.order_id = orderId;
        this.showSystemPopup = true;
        this.showOrderDetailPopup = true;
        this.systemPopupTitle = "确认订单";
      },
      //获取单个订单数据
      getOrderDetail(searchKeyWords) {
        this.order = "";
        this.confirmTotalList = [];
        let _this = this;
        let ourls =
          this.urls +
          "/who/user/refreshToken/" +
          localStorage.getItem("uid") +
          "/" +
          localStorage.getItem("token");
        checkTime(
          new Date().getTime() / 1000,
          ourls,
          localStorage.getItem("reToken")
        );
        _this
          .$http({
            url: this.urls +
              "/who/order/getOrderDetail/" +
              localStorage.getItem("uid") +
              "/" +
              localStorage.getItem("token") + "?order_id=" + searchKeyWords,
            method: "get"
          })
          .then(function(res) {
            let data = res.data;
            if (data.code == 1) {
              _this.order = data.data.order;
              for (var i = 0; i < data.data.order.medical_list.length; i++) {
                _this.confirmTotalList.push(data.data.order.medical_list[i].total);
              }
              localStorage.setItem("nowTimes", new Date().getTime() / 1000); //检查token失效函数
            } else {
              _this.messageAlert(data.msg);
              invalid(data.msg); //检查token失效函数
            }
          })
          .catch(function(error) {
            console.log(error);
          });
      },
      //确定有货数量输入框的change事件
      changeTotalNum(orgTotal, newTotal, index, id) {
        if(checkInputValue(newTotal,3) == 0){
          this.messageAlert("确认确定有货数量只能是整数");
          return;
        }
        if (orgTotal < newTotal) {
          this.messageAlert("确认确定有货数量不能大于客户下单数量");
          this.$refs.enoughDrug[index].style.display = "none"
          this.$refs.lackDrug[index].style.display = "none"
          this.changeStatus = false;
          return;
        } else if (orgTotal == newTotal) {
          this.$refs.enoughDrug[index].style.display = "block";
          this.$refs.lackDrug[index].style.display = "none";
          this.changeStatus = true;
        } else if (orgTotal > newTotal) {
          this.changeStatus = false;
          this.$refs.enoughDrug[index].style.display = "none"
          this.$refs.lackDrug[index].style.display = "block"
        }else{
          this.changeStatus = true;
        }
        if (this.new_medical_list.length <= 0) {
          this.new_medical_list.push({
            medical_id: id,
            total: newTotal
          });
        } else {
          for (var i = 0; i < this.new_medical_list.length; i++) {
            if (this.new_medical_list[i].medical_id == id) {
              this.new_medical_list[i].total = newTotal;
              return;
            }
          }
          this.new_medical_list.push({
            medical_id: id,
            total: newTotal
          });
        }
      },
      //点击确认订单弹窗中的确定
      clickChangeTotal(status) {
        let _this = this;
        let ourls =
          this.urls +
          "/who/user/refreshToken/" +
          localStorage.getItem("uid") +
          "/" +
          localStorage.getItem("token");
        checkTime(
          new Date().getTime() / 1000,
          ourls,
          localStorage.getItem("reToken")
        );
        _this.new_medical_list = JSON.stringify(_this.new_medical_list);
        var data = "";
        if (status == 3) {  //确认订单
          if(!this.changeStatus){
            return;
          }
          data = {
            order_id: _this.order_id,
            new_medical_list: _this.new_medical_list,
            status: 3
          }
        }
        else if(status == 4){  //确认发货

        }
        _this
          .$http({
            url: this.urls +
              "/who/order/changeOrderStatus/" +
              localStorage.getItem("uid") +
              "/" +
              localStorage.getItem("token"),
            method: "post",
            data: data,
            transformRequest: [function(data) {
              let ret = ''
              for (let it in data) {
                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
              }
              return ret
            }],
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            },
          })
          .then(function(res) {
            let data = res.data;
            if (data.code == 1) {
              _this.hideSystemPopup();
              localStorage.setItem("nowTimes", new Date().getTime() / 1000); //检查token失效函数
            } else {
              _this.messageAlert(data.msg);
              invalid(data.msg); //检查token失效函数
            }
          })
          .catch(function(error) {
            console.log(error);
          });
      },
      checkAllFun() {
        //实现全选（1/5）
        var _this = this;
        this.checkArr = [];
        if (this.cheackAllChecked) {
          this.tableList.forEach(function(item, index) {
            if (index >= 0) {
              _this.checkArr.push(item.id);
            }
          });
        }
      },
      reverseChecked() {
        //实现反选（2/5）
        var _this = this;
        var changeArr = [];
        this.tableList.forEach(function(item, index) {
          if (index >= 0) {
            changeArr.push(item.id);
          }
        });
        this.removeByValue(changeArr, this.checkArr);
      },
      removeByValue(changearr, checkarr) {
        //反选过滤函数（3/5）
        var _this = this;
        for (var j = 0; j < checkarr.length; j++) {
          for (var i = 0; i < changearr.length; i++) {
            if (changearr[i] === checkarr[j]) {
              changearr.splice(i, 1);
              break;
            }
          }
        }
        this.checkArr = changearr;
        if (changearr.length <= _this.checkCompleteArr.length) {
          this.cheackAllChecked = false;
        }
        if (changearr.length === _this.checkCompleteArr.length) {
          this.cheackAllChecked = true;
        }
      },
      changevalue() {
        //选项的change事件（4/5）
        var _this = this;
        if (this.checkArr.length <= _this.checkCompleteArr.length) {
          this.cheackAllChecked = false;
        }
        if (this.checkArr.length === _this.checkCompleteArr.length) {
          this.cheackAllChecked = true;
        }
      },
      addPath(n1, n2) {
        //点击切换home-bar
        var obj = {};
        obj.n1 = n1;
        obj.n2 = n2;
        this.$store.commit("addPath", obj);
      },
      //切换路由重新请求数据
      determineRouting(tit, status) {
        this.currentPageName = tit;
        this.showStatus = status;
        this.moreScreeningKeywordList = [];
        this.moreScreeningKeywordList = this.moreScreeningKeywordList_org[status].moreScreeningKeywordList;
        this.iconDownSwitch = false;
        if (this.moreScreeningKeywordList.length > 0) {
          this.iconDownSwitch = true;
        }
        this.getList();
        this.moreScreeningKeyword = false;
      }
    },
    filters: {
      statusFun(val) {
        var data = "";
        if (val == 1) {
          data = "待付款"
        } else if (val == 2) {
          data = "待受理";
        } else if (val == 3) {
          data = "待发货";
        } else if (val == 4) {
          data = "待收货";
        } else if (val == 5) {
          data = "已完成";
        }
        return data;
      },
    },
    watch: {
      'searchKeyWords': function(val) {
        if (this.searchKeyWords.length <= 0) {
          this.getList();
        }
      }
    },
  };
</script>

<style lang="less">
  @import "orderManagement.less";
</style>

